import $ from "@/static/common/js/jquery-3.7.1.min.js";
import '@/components/page-flip/common/turn.js';
	
/**
 * 初始化
 * @param magazineId （dom）
 * @param pcBox (父盒子)
 */
export const magazineInit =  function (magazineId, pcBox){
	let turnPage = 1;
	$(function() {
		var platform_w = $(window).width();
		var displayType = 'single';
		var w = $(window).width();
		var h = $(window).height();
		if(parseInt(platform_w) <= 750){
			$(magazineId).width(w).height(h);
			$(window).resize(function() {
				w = $(window).width();
				h = $(window).height();
				$(magazineId).width(w).height(h);
			});
			displayType = 'single';
		}else{
			// w = pcW;
			// h = pcH;
			w = $(pcBox).width();
			h = $(pcBox).height();
			displayType = 'double';
		}
		$(magazineId).turn({
			width: w,
			height: h,
			elevation: 50,
			page: turnPage,
			display: displayType, 
			gradients: true, 
			autoCenter: true //The full screen effect must be guaranteed not to deform (test conclusion)
		})
	});
}

export const apppx  = function(){
	return $(window).width();
}

/**
 * 左滑
 * @param magazineId 
 */
export const touchLeft = function (magazineId){
	var pageCount = $(magazineId).turn("pages"); //total page
	var currentPage = $(magazineId).turn("page"); //now page
	if (currentPage >= pageCount) {
		return;
	}
	if (currentPage <= pageCount) {
		$(magazineId).turn('page', currentPage + 1);
	}
}

/**
 * 右滑
 * @param magazineId
 */
export const touchRight = function (magazineId){
	var pageCount = $(magazineId).turn("pages"); 
	var currentPage = $(magazineId).turn("page");
	if (currentPage <= pageCount) {
		if (currentPage <= 1) {
			return;
		}
		$(magazineId).turn('page', currentPage - 1);
	}
}

/**
 * 获取当前的页码
 * @param magazineId
 */
export const getPageNumber = function(magazineId){
	let page = $(magazineId).turn('page');
	return page;
}


